/*
 * nglist.h
 */

#include "newsgroup.h"
#include "article.h"

typedef struct NgNode NgNode;
typedef struct ANode ANode;

class NgList {
    public:
        /* Create an empty list */
        NgList();
        /* Destructor */
        ~NgList();

        /* Insert a new node at the end? */
        void addNg(Newsgroup* ng);
        void addArticle(Newsgroup*, Article);
        /* Delete newsgroup */
        void delNg(int id);

    private:
        /* Node */
        struct ANode {
            Article* a;
            ANode* next;
            ~ANode();
            ANode(Article* a = NULL, ANode* next = 0);
        };
        struct NgNode {
            Newsgroup* ng;  		// pointer to newsgroup
            ANode* articles; 	// pointer to articles in newsgroup
            NgNode* next;  		// the pointer to the next node, 0 in the last node

            NgNode(Newsgroup* ng = 0, NgNode* next = 0);
            ~NgNode();
        };
        NgNode* find(Newsgroup*) const;

        NgNode* head;
        NgNode* tail;
        int size;

        /* Copy control */
        NgList(const NgList&);
        NgList& operator=(const NgList&);
};
